<style type="text/css">
	.layer_form{
		text-align: center;
		width: 400px;
		height: 280px;
		line-height: 35px;
		font-size: 18px;

	}
	.form_item{
		margin: 20px;
	}
	.form_item_input{
		float: right;
		margin-right:25px;
	}
	.input_long{
		height: 33px;
	}
	.form_item button{
		width:140px;
	}
	
</style>
<script src="__LAYUI__/layui.js"></script>
<link href="__LAYUI__/css/layui.css" rel="stylesheet"/>
<div class="layer_form">  
      <div class="form_item">  
          <label>账 号：</label>  
          <div class="form_item_input">  
              <input type="text" id="username" placeholder="请输入账号" class="input_long layui-input"/>  
          </div>  
      </div>  
      <div class="form_item">  
          <label>密 码：</label>  
          <div class="form_item_input">  
              <input type="password" id="password" placeholder="请输入密码" class="input_long layui-input"/>  
          </div>   
      </div>
      <div class="form_item">
	      <button type="button" id="loginBtn" class="layui-btn layui-btn-normal">登陆</button>
	      <button type="button" id="exitBtn" class="layui-btn layui-btn-normal">取消</button>
      </div>
      
</div>
<script type="text/javascript">
	layui.use(['jquery', 'layer'], function(){ 
	  var $ = layui.$ //重点处
	  ,layer = layui.layer;
	  
	  //后面就跟你平时使用jQuery一样
	  $(function(){
	  	$('#loginBtn').click(function(){
	  		var username = $.trim($("#username").val());
	  		var password = $.trim($("#password").val());

	  		var url = 'http://127.0.0.1/index/Database/userLogin';
	  		var param = {"username":username,"password":password};
	  		$.post(url,param,function(data){
	  			var user = JSON.parse(JSON.stringify(data));
	  			console.log(user);
	  			if (user.code == "0") {
	  				alert("登陆成功！");
	  				parent.window.localStorage.setItem("username", user.username);
	  				if(user.level=='0'){
						parent.window.location.href='admin';
	  				}else if(user.level=='1'){
						parent.window.location.href='staff';
	  				}
					var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
					parent.layer.close(index); //再执行关闭
               }else if(user.code == "1"){
               		alert("密码错误！");
               		$('#password').val('');
               }else if(user.code == "2"){
                	alert("账号不存在！");
                	$('#username').val('');
                	$('#password').val('');
               }
	  		});
	  	});
	  	$('#exitBtn').click(function(){
  			var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
			parent.layer.close(index); //再执行关闭
	  	});
	  });
	});
</script>  
